package com.wyk.springbootdemo.controller;

import com.wyk.springbootdemo.entity.ServerSetings;
import com.wyk.springbootdemo.entity.User;
import com.wyk.springbootdemo.entity.UserTest;
import com.wyk.springbootdemo.mapper.UserAddMapper;
import com.wyk.springbootdemo.mapper.UserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.PropertySource;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
@PropertySource({"classpath:resources/resource.properties"})
public class controller2 {
    @Value("${test.name}")
    private String name;
    @Autowired
    private ServerSetings serverSetings;

    @GetMapping("/index")
    public String index(Map map){
        System.out.println(name);
        System.out.println(serverSetings.getUsername());
        System.out.println(serverSetings.getPwd());
        map.put("name",name);
        return "Index";

    }

//    @GetMapping("/index2")
//    public String index2(Map map){
//
//        map.put("name",name);
//        return "index2";
//
//    }
    @GetMapping("/api/login")
    public String index2(){

        return "index";

    }
    @GetMapping("/error")
    public String error(){

        return "error";

    }
    @Autowired
    private UserMapper userMapper;
    @GetMapping("/index2")
    public String hello2(Map map){
        UserTest user=new UserTest();
        user.setUsername("小老妹");
        user.setPassword("222");
       // userMapper.inset(user);
        map.put("name",name);
        return  "test01";
    }


    @Autowired
    private UserAddMapper userAddMapper;
    @GetMapping("/index3")
    public String hello3(){

      List<UserTest> users= userAddMapper.getAll();
        for (UserTest user: users
             ) {
            System.out.println(user);
        }
        return "index2";
//        int i=userAddMapper.deleteUserById(4);
//        System.out.println(i);
//        return  "index2";
    }
}
